//
//  FR_Visitor_TableViewCell.m
//  FaceRecognition
//
//  Created by zz on 17/7/5.
//  Copyright © 2017年 Sylar. All rights reserved.
//

#import "FR_Visitor_TableViewCell.h"

@interface FR_Visitor_TableViewCell()

@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *visitedLabel; //被访问者
@property (nonatomic, strong) UILabel *startTimeLabel; //访问开始时间
@property (nonatomic, strong) UILabel *endTimeLabel; //访问结束时间
@property (nonatomic, strong) UIButton *stateButton; //状态

@property (nonatomic, strong) UIView *lineView;

@end

@implementation FR_Visitor_TableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
       
        _imgView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 14, 80, 80)];
        _imgView.contentMode = UIViewContentModeScaleAspectFill;
        _imgView.clipsToBounds = YES;
        
        [self.contentView addSubview:_imgView];
        
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_imgView.frame) + 14, 14, 300, 16)];
        _nameLabel.font = [UIFont systemFontOfSize:16];
        _nameLabel.textColor = [UIColor colorWithHexString:@"#000000"];
        _nameLabel.text = @"老王";
        [self.contentView addSubview:_nameLabel];
        
        _visitedLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_imgView.frame) + 14, CGRectGetMaxY(_nameLabel.frame) + 9, 300, 15)];
        _visitedLabel.font = [UIFont systemFontOfSize:15];
        _visitedLabel.textColor = [UIColor colorWithHexString:@"#3b3b3b"];
        _visitedLabel.text = @"访问: 老王";
        [self.contentView addSubview:_visitedLabel];
        
        _startTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_imgView.frame) + 14, CGRectGetMaxY(_visitedLabel.frame) + 5, 300, 15)];
        _startTimeLabel.font = [UIFont systemFontOfSize:15];
        _startTimeLabel.textColor = [UIColor colorWithHexString:@"#3b3b3b"];
        _startTimeLabel.text = @"访问时间 2017   000";
        [self.contentView addSubview:_startTimeLabel];
        
        _endTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_imgView.frame) + 14, CGRectGetMaxY(_startTimeLabel.frame) + 5, 300, 15)];
        _endTimeLabel.font = [UIFont systemFontOfSize:15];
        _endTimeLabel.textColor = [UIColor colorWithHexString:@"#3b3b3b"];
        _endTimeLabel.text = @"结束时间 2017   000";
        [self.contentView addSubview:_endTimeLabel];
        
        _stateButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_stateButton setTitle:@"待处理" forState:UIControlStateNormal];
        [_stateButton setTitle:@"已拒绝" forState:UIControlStateSelected];
        [_stateButton setTitleColor:[UIColor colorWithHexString:@"#f55f5f"] forState:UIControlStateNormal];
        [_stateButton setTitleColor:[UIColor colorWithHexString:@"#979797"] forState:UIControlStateSelected];
        [_stateButton setFrame:CGRectMake(SCREENWIDTH - 50 - 15, 14, 50, 16)];
        _stateButton.titleLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:_stateButton];
        
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(0,CGRectGetMaxY(_imgView.frame) + 13.5, SCREENWIDTH, 0.5)];
        _lineView.backgroundColor = [UIColor colorWithHexString:@"#dedede"];
        [self.contentView addSubview:_lineView];
    }
    
    return self;
}


-(void)setModel:(FR_VisitorModel *)model {
    
    _model = model;
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",REQUESTIMAGEURL,model.photo];
    [_imgView sd_setImageWithURL:[NSURL URLWithString:urlStr]];
    
    _nameLabel.text = model.name;
    _startTimeLabel.text = [NSString stringWithFormat:@"访问时间:%@",model.starttime]; ;
    _visitedLabel.text = [NSString stringWithFormat:@"访问:%@",model.intervieweename];
    _endTimeLabel.text = [NSString stringWithFormat:@"结束时间:%@",model.endtime];
    
    _stateButton.selected = model.approval > 0;
    
    NSString *btnTitle;
    switch (model.approval) {
        case 0:
            btnTitle = @"待处理";
            break;
        case 1:
            btnTitle = @"已接受";
            break;
        case 2:
            btnTitle = @"已拒绝";
            break;
        default:
            break;
    }
    
    [_stateButton setTitle:btnTitle forState:UIControlStateSelected];
    
}

@end
